<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.application.component.model' );
class ModelSimCategoriesSimCategories extends JModel
{
    var $_SimCategories = null;
    var $_id = null;
    var $_Category_name=null;
	
	var $_data = null;
	var $_total = null;
	var $_pagination = null;
	var $_limit = 20;
	var $_limitstart = 0;
	
	
	public function __construct(){
		
		parent::__construct();
		
		$id = JRequest::getVar('id', 0,'int');
        $this->_id = $id;
		
		$mainframe = &JFactory::getApplication();
		$context = JRequest::getCmd('option');
		$view = JRequest::getCmd('view');
		
		//$this->_limit = $mainframe->getUserStateFromRequest( $context.$view.'limit', 'limit', $mainframe->getCfg('list_limit'), 30);
		$limitstart = JRequest::getInt('limitstart');
		//var_dump($limitstart);
		$this->_limitstart = empty($limitstart) ? 0 : $limitstart;
		
		$this->setState('limit', $this->_limit);
		$this->setState('limitstart', $this->_limitstart);
	}
	
	public function getResult(){
	
		$query = $this->_buildQuery();
		//echo $query;
		if (empty($this->_data)){
		
			$this->_db->setQuery( $query, $this->_limitstart, $this->_limit );
			$this->_data = $this->_db->loadObjectList();
		}
		
		$data = $this->_data;
		return $data;
		
	}
	public function _buildQuery(){
		
		$query = "SELECT a.sim_id, a.sim_numb,a.price,a.curency,b.provider_name,c.admin_name FROM #__sim as a,#__sim_provider as b,#__sim_admin c WHERE a.admin_id=c.admin_id and
         a.provider_id = b.provider_id and a.del_flag =0 and a.categori_id = '" . $this->_id . "' order by a.price desc";
		
		return $query; 
		
	}
	public function getTotal(){
		
		if (empty($this->_total)){
			$query = $this->_buildQuery();
			$this->_total = $this->_getListCount($query);
		}
		return $this->_total;
	}

	public function getPagination(){
	
		if (empty($this->_pagination))
		{
			jimport('joomla.html.pagination');
			$this->_pagination = new JPagination( $this->getTotal(), $this->_limitstart, $this->_limit );
		}
		return $this->_pagination;
	}
	
	
    function getSimCategories()
    {
        if(!$this->_SimCategories)
        {
            $query = "SELECT a.sim_id, a.sim_numb,a.price,a.curency,b.provider_name,c.admin_name FROM #__sim as a,#__sim_provider as b,#__sim_admin c WHERE a.admin_id=c.admin_id and
         a.provider_id = b.provider_id and a.del_flag =0 and a.categori_id = '" . $this->_id . "' order by a.price desc";
            
			$this->_SimCategories = $this->_getList($query);
        }
        return $this->_SimCategories;
    }
    function getCategoryName(){
        $query = "select categori_name from #__sim_categories where del_flag=0 and categori_id=". $this->_id ;
        $this->_Category_name = $this->_getList($query);
        return $this->_Category_name;
    }
}
?>